using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.AcmsControls
{
    public class TextContentControlDisplay : BaseContentControlDisplay
    {
        private TextContentControlProperties properties;
        protected TextContentControlProperties Properties
        {
            get
            {
                if (properties == null)
                {
                    properties = new TextContentControlProperties();
                }
                return properties;
            }
        }

        private string text;

        protected override BaseContentControlProperties GetProperties()
        {
            return Properties;
        }

        protected override void SetProperties(BaseContentControlProperties properties)
        {
            this.properties = properties as TextContentControlProperties;
            if (this.Properties != null)
            {
                this.text = this.Properties.Text;
            }
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(text))
            {
                if (!string.IsNullOrEmpty(WrapperTag))
                    writer.RenderBeginTag(WrapperTag);
                writer.Write(text);
                if (!string.IsNullOrEmpty(WrapperTag))
                    writer.RenderEndTag();
            }
        }

        protected override object SaveViewState()
        {
            ViewState["Text"] = text;
            return base.SaveViewState();
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            text = ViewState["Text"] as string;
        }

        private string wrapperTag;
        public string WrapperTag
        {
            get { return wrapperTag; }
            set { wrapperTag = value; }
        }
	
    }
}
